package cn.apthink.controller.system;

import java.util.List;

import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;

import cn.apthink.controller.BaseResult;
import cn.apthink.controller.DataResult;
import cn.apthink.model.UParameter;
import cn.apthink.service.SystemService;
import cn.apthink.solon.Logging;
import cn.dev33.satoken.stp.StpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * 系统
 *
 * @author David唐
 * @createdate 2024年2月7日
 */
@Logging
@Slf4j
@Controller
@Api(value="系统控制器")
@Mapping("/api")
public class SystemController {
	@Inject
	SystemService systemService;

	@Mapping("/systemparameter")
	@ApiOperation("获取系统参数信息")
	public BaseResult systemparameter(@ApiParam(name = "id", value = "参数id", required = true) String id) {
		log.debug("systemparameter", id);
		return DataResult.success("获取参数成功", systemService.getSystemParameter(id));
	}

	@Mapping("/systemparameters")
	@ApiOperation("获取多个系统参数信息")
	public BaseResult systemparameters(@Body @ApiParam(name = "ids", value = "参数id集", required = true) List<String> ids) {
		log.debug("systemparameters", ids);
		return DataResult.success("获取参数成功", systemService.getSystemParameter(ids));
	}

	@Mapping("/savesystemparameter")
	@ApiOperation("保存用户参数信息")
	public BaseResult savesystemparameter(@ApiParam(name = "parameter", value = "参数对象", required = true) UParameter param) {
		log.debug("savesystemparameter", param);
		systemService.saveSystemParameter(param);
		return BaseResult.success("保存用户参数成功");
	}

	@Mapping("/userparameter")
	@ApiOperation("获取用户参数信息")
	public BaseResult userparameter(@ApiParam(name = "id", value = "参数id", required = true) String id) {
		String userid = (String) StpUtil.getLoginId();
		log.debug("systemparameters", id, userid);
		return DataResult.success("获取参数成功", systemService.getUserParameter(userid, id));
	}

	@Mapping("/saveuserparameter")
	@ApiOperation("保存用户参数信息")
	public BaseResult saveuserparameter(@ApiParam(name = "parameter", value = "参数对象", required = true) UParameter param) {
		String userid = (String) StpUtil.getLoginId();
		log.debug("saveuserparameter", param, userid);
		systemService.saveUserParameter(userid, param);
		return BaseResult.success("保存用户参数成功");
	}

	@Mapping("/userparameters")
	@ApiOperation("获取多个用户参数信息")
	public BaseResult userparameters(@Body @ApiParam(name = "ids", value = "参数id集", required = true) List<String> ids) {
		String userid = (String) StpUtil.getLoginId();
		log.debug("systemparameters", ids, userid);
		return DataResult.success("获取参数成功", systemService.getUserParameter(userid, ids));
	}

	@Mapping("/systemdata")
	@ApiOperation("获取系统参数信息")
	public BaseResult systemdata() {
		return DataResult.success("获取参数成功", systemService.getSystemData());
	}
}